package com.jiyun.controller;

import com.jiyun.mapper.NCardMapper;
import com.jiyun.pojo.NBank;
import com.jiyun.pojo.NCard;
import com.jiyun.service.NBankService;
import com.jiyun.service.NCardService;
import com.jiyun.utils.R;
import com.jiyun.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/NCard")
public class NCardController {

    @Autowired
    private NCardMapper nCardMapper;
    @Autowired
    private NCardService nCardService;

    @Autowired
    private NBankService nBankService;

    @GetMapping("/findAll")
    public List<NCard> findAll() {
        return nBankService.findAll();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        nBankService.removeById(id);
        return Result.ok();
    }

    @PostMapping("/deleteId")
    public int deleteId(Integer id) {
        return nCardService.deleteId(id);
    }

    @PostMapping("/add")
    public R yhk(@RequestBody NCard nCard) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
        return nBankService.yhk(nCard);
    }
    @GetMapping("/findCard")
    public  NCard findCard(@RequestParam("id") Integer id){
        return nCardMapper.findCard(id);
    }
    @GetMapping("/updateStatus")
    public int updateStatus(@RequestParam("id") Integer id){
        return nCardService.updateStatus(id);
    }
    @GetMapping("/updateStatus2")
    public int updateStatus2(@RequestParam("id") Integer id){
        return nCardService.updateStatus2(id);
    }
}
